<?php

class DB_ANALYSIS_USER extends ORM_Table {
    
    static $users   = array();
    static protected $table_name = 'analysis_user';
    
    static public function getTableName($params = null) {
        return self::$table_name;
    }

    /**
     * 批量保存
     * @param type $users Ta的粉丝
     * @return type 
     */
    static function batch_save($users){
        
        if(empty($users)){
            return null;
        }
        
        foreach ($users as $k => $v){
            //添加标签
            DB_TAG::store($v['id'], 'n');
            
            $weibo   = ORM_Finder::findOne('DB_ANALYSIS_USER', array('weibo_id'=>$v['id']),'id');
            if(!$weibo){
                $weibo  = new DB_ANALYSIS_USER();
            }
            
            $weibo->setWeiboId($v['id']);
            $weibo->setScreenName($v['screen_name']);
            $weibo->setGender($v['gender']);
            if($v['verified']){
                $weibo->setVerified(1);
            }
            $weibo->setFollowersCount($v['followers_count']);
            $weibo->setFriendsCount($v['friends_count']);
            $weibo->setStatusesCount($v['statuses_count']);
            $weibo->setFavouritesCount($v['favourites_count']);
            if($v['allow_all_act_msg']){
                $weibo->setAllowSend(1);
            }
            $created_at = date('Y-m-d',  strtotime($v['created_at']));
            $weibo->setCreatedAt($created_at);
            $weibo->setFetchCount($v['fetch_count']);
            $weibo->save();
            self::$users[]  = $weibo;
        }
        return self::$users;
    }    
}

?>
